package com.neusoft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.neusoft.mapper.RoleMapper;
import com.neusoft.mapper.UserMapper;
import com.neusoft.po.Role;
import com.neusoft.po.User;

@Service
public class UserService {
	@Autowired
	private UserMapper userMapper;
	public User getUser() throws Exception{
		return userMapper.findUserById(23);
	}
	public void updateUser(){
		User user = new User();
		user.setUsername("真武.安逸恒12");
		user.setId(54);
		userMapper.updateUserById(user);
	}
	public void delUser(){
		userMapper.delUserById(50);
	}
	public void addUser(){
		User user = new User();
		user.setUsername("神武.安逸恒");
		user.setSex("男");
		user.setBirthday(new java.sql.Date(new java.util.Date(96,0,21).getTime()));
		user.setAddress("卡门");
		userMapper.addUser(user);
	}
	public void getAllRole(){
		List<Role> list = userMapper.getAllRole();
		for(Role role:list){
			System.out.println("权限:"+role.getRolename()+":"+role.getRoleinfo());
			List<User> users = role.getUsers();
			for(User u:users){
				System.out.println("包含用户："+u.getUsername()+":"+u.getId());
			}
			System.out.println("--------------------");
		}
	}
}
